-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: use data-service sessions endpoint #3296
feat: use data-service sessions endpoint #3296
Conversation
You can access the deployment of this PR at https://renku-ci-ui-3296.dev.renku.ch |
a1a5479
to
816e188
Compare
816e188
to
1086ab6
Compare
1086ab6
to
fbc0695
Compare
a03efa6
to
0df603e
Compare
283294d
to
deaa61a
Compare
0df603e
to
26364df
Compare
deaa61a
to
dbe673e
Compare
f059742
to
26d6197
Compare
0522b87
to
57e03e7
Compare
edb9a9d
to
113e0cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General note: please use the function
style for components.
A first batch of comments below:
client/src/components/LogsV2.tsx
Outdated
interface EnvironmentLogsPropsV2 { | ||
name: string; | ||
} | ||
export const EnvironmentLogsV2 = ({ name }: EnvironmentLogsPropsV2) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client/src/components/LogsV2.tsx
Outdated
if (!logs?.show || logs?.show !== name || !logs) return null; | ||
|
||
return ( | ||
<Modal | ||
isOpen={!!logs.show} | ||
className="modal-xl" | ||
scrollable={true} | ||
toggle={() => { | ||
toggleLogs(name); | ||
}} | ||
> | ||
<ModalHeader | ||
className="header-multiline" | ||
toggle={() => { | ||
toggleLogs(name); | ||
}} | ||
> | ||
<div>Logs</div> | ||
</ModalHeader> | ||
<ModalBody> | ||
<div className="mx-2"> | ||
<SessionLogs fetchLogs={fetchLogs} logs={logs} name={name} /> | ||
</div> | ||
</ModalBody> | ||
</Modal> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this split into another component here? This code can be in the previous component and that saves all the interface
and const =
lines of code.
@@ -86,13 +86,13 @@ function AddSessionEnvironmentModal({ | |||
addSessionEnvironment({ | |||
container_image: data.container_image, | |||
name: data.name, | |||
default_url: data.default_url.trim() ? data.default_url : undefined, | |||
description: data.description.trim() ? data.description : undefined, | |||
default_url: data.default_url?.trim() ? data.default_url : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For here and everywhere else: should we instead have this?
default_url: data.default_url?.trim() ? data.default_url : undefined, | |
default_url: data.default_url?.trim() || undefined, |
Otherwise we send untrimmed
strings to the API.
This can be added to a new issue to do later.
{session?.status?.will_hibernate_at && | ||
session?.status?.will_hibernate_at?.length > 0 && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for a length check on strings:
{session?.status?.will_hibernate_at && | |
session?.status?.will_hibernate_at?.length > 0 && ( | |
{session?.status?.will_hibernate_at && ( |
Please note that paused session are deleted after{" "} | ||
{hibernationThreshold} of inactivity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an accurate text copy because session?.status?.will_hibernate_at
refers to this specific session. Also the text refers to "DELETE"
while the threshold is for "PAUSE"
.
const hibernationThreshold = session?.status?.will_hibernate_at | ||
? toHumanRelativeDuration({ | ||
datetime: session?.status?.will_hibernate_at, | ||
now, | ||
}) | ||
: 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make things correct, it is preferable to use <TimeCaption>
instead of computing this. <TimeCaption>
supports passing class names and the noCaption
attribute to not have the time-caption
class.
throw new Error("Unsupported protocol"); | ||
} catch (error) { | ||
if (url && !url.includes("://")) { | ||
return `https://${url}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this is not a valid URL?
session: SessionV2; | ||
} | ||
|
||
export default function SessionIframe({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New issue: re-factor into existing <SessionJupyter>
component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -88,12 +85,15 @@ export default function ShowSessionPage() { | |||
slug: slug ?? "", | |||
}); | |||
|
|||
const { data: sessions, isLoading } = useGetSessionsQuery(); | |||
const { data: sessions, isLoading } = useGetSessionsQuery(undefined, { | |||
skip: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good! I have some small code suggestions and a question about intent, but those are all quite minor.
We discussed the use of anonymous vs. named functions for the components, and it looks like the project session test is failing, but I'm assuming you are already work on those.
default_url: data.default_url?.trim() ? data.default_url : undefined, | ||
description: data.description?.trim() ? data.description : undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would this code should actually be this:
default_url: data.default_url?.trim() ? data.default_url : undefined, | |
description: data.description?.trim() ? data.description : undefined, | |
default_url: data.default_url?.trim() ? data.default_url.trim() : undefined, | |
description: data.description?.trim() ? data.description.trim() : undefined, |
or maybe even better, introduce a function:
function trimmedOrUndefined(value: string | undefined) {
return value?.trim() ? value.trim() : undefined;
}
@@ -105,13 +105,13 @@ function UpdateSessionEnvironmentModal({ | |||
environmentId: environment.id, | |||
container_image: data.container_image, | |||
name: data.name, | |||
default_url: data.default_url.trim() ? data.default_url : "", | |||
description: data.description.trim() ? data.description : "", | |||
default_url: data.default_url?.trim() ? data.default_url : "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the comment on AddSessionEnvironmentButton
:
function trimmedOrEmpty(value: string | undefined) {
return value?.trim() ? value.trim() : "";
}
statusData?.ready_containers && statusData?.total_containers | ||
? `${statusData?.ready_containers} of ${statusData?.total_containers} containers ready` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be safe:
statusData?.ready_containers && statusData?.total_containers | |
? `${statusData?.ready_containers} of ${statusData?.total_containers} containers ready` | |
statusData?.ready_containers && statusData?.total_containers | |
? `${statusData.ready_containers} of ${statusData.total_containers} containers ready` |
Please note that paused session are deleted after{" "} | ||
{hibernationThreshold} of inactivity. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that paused session are deleted after{" "} | |
{hibernationThreshold} of inactivity. | |
Please note that paused sessions are deleted after{" "} | |
{hibernationThreshold} of inactivity. |
@@ -577,12 +556,12 @@ function ModifySessionModalContent({ | |||
useEffect(() => { | |||
const currentSessionClass = resourcePools | |||
?.flatMap((pool) => pool.classes) | |||
.find((c) => c.id === currentSessionClassId); | |||
.find((c) => `${c.id}` == resource_class_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be more idiomatic.
.find((c) => `${c.id}` == resource_class_id); | |
.find((c) => ""+ c.id == resource_class_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a javascript "hack" and should not be used. It uses type coercion so this makes code look weird (see things like "1"+1 == 11
, etc. ${c.id}
is a valid way to convert a number
to a string
.
(resource_class_id != null && | ||
resource_class_id === `${currentSessionClass?.id}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this logic is used in a couple of places:
(resource_class_id != null && | |
resource_class_id === `${currentSessionClass?.id}`) | |
resourceClassMatchesCurrent(resource_class_id, currentSessionClass) |
function resourceClassMatchesCurrent(resourceClassId: string | undefined, currentSessionClass: string) {
return (resourceClassId != null && resourceClassId === ""+currentSessionClass.id)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just?
resource_class_id === `${currentSessionClass?.id}
This is all that's needed here (resource_class_id
cannot be null-ish and equal a string).
(resource_class_id != null && | ||
resource_class_id === `${currentSessionClass?.id}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(resource_class_id != null && | |
resource_class_id === `${currentSessionClass?.id}`) | |
resourceClassMatchesCurrent(resource_class_id, currentSessionClass) |
providesTags: (result) => | ||
result | ||
? [ | ||
...result.map(({ name }) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: name
is used here, but id
below. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name
field is the identifier. Maybe that should be changed in the API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the change has been requested. I will implement this in a future PR once the updates are made in the API.
04c6d02
to
5c9eb97
Compare
- use named functions - refactor working and mount directory handling with optional chaining and fallback to undefined - remove forced URL generation in ensureHTTPS function when the input is not a valid URL. - ensure session data is fetched when loading ShowSessionPage
bcf8906
to
be32e65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good to go after these comments.
@@ -105,15 +105,11 @@ function UpdateSessionEnvironmentModal({ | |||
environmentId: environment.id, | |||
container_image: data.container_image, | |||
name: data.name, | |||
default_url: data.default_url.trim() ? data.default_url : "", | |||
description: data.description.trim() ? data.description : "", | |||
default_url: data.default_url?.trim() ? data.default_url : "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this can be done here as well:
default_url: data.default_url?.trim() ? data.default_url : "", | |
default_url: data.default_url?.trim() || "", |
import { NotebooksHelper } from "../../notebooks"; | ||
import { NotebookAnnotations } from "../../notebooks/components/session.types"; | ||
import { useGetSessionsQuery as useGetSessionsQueryV2 } from "../../features/sessionsV2/sessionsV2.api"; | ||
import "../../notebooks/Notebooks.css"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you keep the CSS imports as the last ones? They semantically different from the other ones, so we should make them stand out. Also keep the associated comment.
- add file comment - move css import ant the end of the import list - simplify default_url and description assignment to simplify conditional check
|
||
// Required for logs formatting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you keep this comment here? Otherwise there is no indication that removing the .css
import would break something.
- Restore the CSS import comment to prevent the removal of log styles
Tearing down the temporary RenkuLab deplyoment for this PR. |
PR to use data-service
/sessions/*
endpoint in Renku V2.What's Included
What's Not Included‼️
Pending
/deploy renku=feat-jupyter-free-sessions renku-data-services=release-amaltheas-migration amalthea-sessions=main renku-notebooks=master renku-gateway=1.1.0 extra-values=amalthea-sessions.deployCrd=false